package com.search.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FirstEndOfMonth {
	private static Calendar c = Calendar.getInstance();
	/**
	 * 获取系统时间的第一天
	 * @param sYear
	 * @param sMonth
	 * @return
	 */
	public static String getFirstDayofMonth(int sYear, int sMonth) {
		String tStartdate = "";
		c.set(Calendar.YEAR, sYear);
		c.set(Calendar.MONTH, sMonth);
		tStartdate = String.valueOf(sYear) + "-" + String.valueOf(sMonth) + "-0"
				+ c.getActualMinimum(Calendar.DAY_OF_MONTH);
		return tStartdate;

	}
	/**
	 * 获取系统时间最后一天
	 * @param sYear
	 * @param sMonth
	 * @return
	 */
	public static String getEndDayofMonth(int sYear, int sMonth) {
		String tEnddate = "";
		c.set(Calendar.YEAR, sYear);
		c.set(Calendar.MONTH, sMonth-1);
		c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));  
		int i =c.getActualMaximum(Calendar.DAY_OF_MONTH);
		tEnddate = String.valueOf(sYear) + "-" + String.valueOf(sMonth) + "-"
				+ String.valueOf(i);
		return tEnddate;
	}
	/**
	 * 获取系统时间的所在周的第一天
	 * @return
	 */
	public static String getFirstWeekDay() {
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期
		return df.format(cal.getTime());
	}
	/**
	 * 获取系统时间的所在周的最后一天
	 * @return
	 */
	public static String getLastWeekDay() {
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		cal.add(Calendar.WEEK_OF_YEAR, 1);
		return df.format(cal.getTime());
	}
}
